/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ManagedBeans;

import Processes.Navigate;
import java.io.Serializable;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import radio.entities.Accounts;
import radio.sessions.AccountsFacade;

/**
 *
 * @author Kim
 */
public class Register implements Serializable{
   
    @EJB
    private AccountsFacade accountsFacade;
    
    private String companyname,designation,fax;
    private String uid,pwd,confirm,contact,mobile,tele,address,email;
    private int cityid;
    private boolean gender;
    
    public boolean isGender() {
        return gender;
    }

    public void setGender(boolean gender) {
        this.gender = gender;
    }
    /** Creates a new instance of Register */
    public Register() {
    }

    public String getConfirm() {
        return confirm;
    }

    public void setConfirm(String confirm) {
        this.confirm = confirm;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public int getCityid() {
        return cityid;
    }

    public void setCityid(int cityid) {
        this.cityid = cityid;
    }

    public String getContact() {
        return contact;
    }

    public void setContact(String contact) {
        this.contact = contact;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public String getTele() {
        return tele;
    }

    public void setTele(String tele) {
        this.tele = tele;
    }

    public String getUid() {
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }
    
    public String regis(){
        //HttpSession ses=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);   
        //ses.invalidate();
        Accounts temp=accountsFacade.findbyUsername(this.uid);
        if(temp!=null){
            FacesContext cxt=FacesContext.getCurrentInstance();
            cxt.addMessage("RegisForm:username",new FacesMessage("Username is not available !"));
         return "";   
        }else if(!this.pwd.equalsIgnoreCase(this.confirm)) {
            FacesContext cxt=FacesContext.getCurrentInstance();
            cxt.addMessage("RegisForm:confirm",new FacesMessage("Confirm password does not match !"));
            return "";
        }else{
        boolean abc=accountsFacade.insertnewAcc(uid, pwd, gender, cityid, contact, mobile, tele, address, email);
            System.out.println(abc);            
            FacesMessage msg = new FacesMessage("Registered Successful");            
            FacesContext.getCurrentInstance().addMessage(null, msg);
        Navigate nav=(Navigate) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("navigate");
        nav.setPage(null);            
        return "MainPage.xhtml";        
        }
    }

    public String getCompanyname() {
        return companyname;
    }

    public void setCompanyname(String companyname) {
        this.companyname = companyname;
    }

    public String getDesignation() {
        return designation;
    }

    public void setDesignation(String designation) {
        this.designation = designation;
    }

    public String getFax() {
        return fax;
    }

    public void setFax(String fax) {
        this.fax = fax;
    }
    
}
